Bulk Messaging System

Documentation

Whats app integration

Introduction#

This page explains the WhatsApp Web integration for bulk messaging, focusing on QR code authentication, session and connection lifecycle, contact import from CSV, Excel, and text files, message composition with personalization, bulk sending with configurable delays, and real-time status monitoring. It also covers troubleshooting and security best practices.

Project structure#

The integration spans three layers:

  • Electron renderer (React UI) for user interaction and status display
  • Electron main process for WhatsApp Web.js client lifecycle and IPC
  • Python backend for advanced contact processing and validation

Core components#

  • WhatsAppForm: UI for connecting, scanning QR, managing contacts, composing messages, and viewing activity logs.
  • BulkMailer: Orchestrates WhatsApp lifecycle, listens to status events, and coordinates IPC with the main process.
  • Electron Main: Initializes the WhatsApp client, handles QR generation, connection events, and bulk sending loop with delays.
  • Preload Bridge: Exposes secure IPC methods to the renderer for WhatsApp operations.
  • Python Backend: Provides REST endpoints for contact import and parsing, including CSV/Excel/Text support and number validation.

Architecture overview#

End-to-end flow for authentication and sending:

Detailed component analysis#

QR code authentication and session lifecycle#

  • The main process creates a Client with LocalAuth and emits QR codes as data URLs.
  • The renderer displays QR until authentication succeeds or errors occur.
  • Logout triggers explicit client logout and cleanup of cached auth/session files.

Contact import and parsing#

  • CSV/Excel/Text import is supported via two paths:
    • Python backend REST endpoints for reliable parsing and validation
    • Manual text parsing in the renderer using Pyodide for quick local processing
  • The renderer supports CSV/Text locally; Excel is noted as not yet supported in this UI path.

Message composition and personalization#

  • Users compose messages in the UI and can use a placeholder to personalize with contact names.
  • During sending, the message is personalized by replacing the placeholder with either the contact’s name or a default value.

Bulk sending implementation and delays#

  • The main process sends messages sequentially to each contact.
  • It checks registration status before sending and applies delays to reduce spam risk.
  • Real-time progress is emitted via IPC to the renderer for display.

Real-time status monitoring#

  • The renderer subscribes to three event channels:
    • Connection status updates
    • QR code data URL updates
    • Per-message send status updates
  • These are displayed in the activity log with color-coded indicators.

Dependency analysis#

Key runtime dependencies for the integration:

  • whatsapp-web.js: Core WhatsApp Web client and authentication
  • qrcode: QR code rendering for the UI
  • Pyodide and Python backend: Contact parsing and validation utilities

Performance considerations#

  • Sequential sending with delays reduces rate limits and improves reliability.
  • Using isRegisteredUser avoids unnecessary send attempts and reduces error noise.
  • QR generation occurs only once per session; caching and reuse minimize overhead.
  • Consider batching contacts and adding jitter to delays for natural pacing.

Troubleshooting guide#

Common issues and resolutions:

  • QR code not loading
    • Refresh the client and retry; the UI provides a retry button when QR fails to load.
    • Ensure network connectivity and try again.
  • Authentication failures
    • Reinitialize the client and re-scan the QR.
    • Confirm the device is linked and not logged out elsewhere.
  • Rate limiting and spam detection
    • Increase delays between messages; the current implementation uses fixed delays.
    • Pause periodically and resume to avoid continuous bursts.
  • Contact import errors
    • Verify file format and encoding; supported formats include CSV, Excel (.xlsx/.xls), and Text.
    • Ensure phone numbers are valid and standardized before sending.

Security considerations#

  • Context isolation and secure IPC prevent direct Node.js access in the renderer.
  • LocalAuth stores session securely; logout clears cached auth files.
  • Input validation and sanitization are applied in the Python backend for numbers and contact parsing.
  • Use strong authentication for external services (Gmail/SMTP) and rotate credentials regularly.

Conclusion#

The integration provides a reliable, user-friendly pathway to authenticate via QR, manage contacts, compose personalized messages, and send them reliably with real-time feedback. The architecture cleanly separates concerns across renderer, main process, and Python utilities, enabling maintainability and scalability.